//
//  GoodsSpec.swift
//  eemall
//
//  Created by zhuxietong on 2018/9/27.
//  Copyright © 2018 zhuxietong. All rights reserved.
//

import Foundation
import Eelay
import soapp

public struct GoodsSpec{
    
    public init(goods:NSMutableDictionary) {
        self.rawValue = goods
    }
    
    public var rawValue:NSMutableDictionary
    
    
    
    public var needAdress:Bool{
        get{
            var need = rawValue[Goods.key_needAddress,false.tag] == true.tag
            if isOfflineVerification
            {
                need = false
            }
            return need
        }
    }
    public var isOfflineVerification:Bool{
        get{
            return rawValue[Goods.key_isverify,false.tag] == true.tag
        }
    }
    
    public var uisection_address:[[String:Any]]{
        get{
            let address = DataNode.path(node: "address", rawValue, value: NSMutableDictionary())
            var addressSection = [[String:Any]]()
            if self.needAdress
            {
                addressSection = [
                    ["id":"line8"],
                    ["cellID":"address","address":address],
                ]
            }
            return addressSection
        }
    }
    
    //线下核销商品需要用核销码需要填写姓名电话
    public var uisection_verification_person:[[String:Any]]{
        get{
            let info = JoUser.loginUser()?.info ?? NSMutableDictionary()
            var sec = [[String:Any]]()
            if isOfflineVerification{
                
                var addresses = [[String:Any]]()
                var ad_list = DataNode.path(node: "order.verifystores", rawValue, value: NSMutableArray())//艾维老版本的获取地址
                if ad_list.count < 1{
                    ad_list = DataNode.path(node: "stores.list", rawValue, value: NSMutableArray())
                }
                if ad_list.count > 0
                {
                    ad_list.list { (obj:NSMutableDictionary, i) in
                        if i == 0{
//                            addresses.append(
//                                ["cellID":"blank","height":"8"]
//                            )
                            addresses.append(
                                ["cellID":"verifyAddressTitle","title":"地址".loc,"tag":"更多".loc,"__model":rawValue,"total":rawValue["stores.total","0"]]
                            )
                        }
                        obj["cellID"] = "verifyAddress"
                        addresses.append(obj.swift_dictionary)
                    }
                }
                
                
                sec = [
                    ["cellID":"offlinenote"],
                    [
                        "title":"姓名".loc,
                        "cellID":"name",
                        FK.fields:[
                            [
                                FK.placeholder:"输入姓名".loc,
                                FK.value:info["nickname",""],
                                FK.field:StrField(id: "carrier_realname", defaultV: nil, need: true, hiden: false, rule:
                                    JoRule(reg: "^[\\s\\S]{1,100000}$", nil_msg: "请输入姓名".loc, err_msg: "检查姓名".loc))
                            ]
                        ],
                        ],
                    [
                        "title":"手机号".loc,
                        "cellID":"mobile",
                        FK.fields:[
                            [
                                FK.placeholder:"输入手机号".loc,
                                FK.value:info["mobile",""],
                                FK.field:StrField(id: "carrier_mobile", defaultV: nil, need: true, hiden: false, rule:
                                    JoRule(reg: EeLogin.phone, nil_msg: "请输入手机号".loc, err_msg: "检查手机号".loc))
                                
                            ]
                        ],
                    ]
                ]
                sec = sec + addresses
            }
            return sec
        }
    }
}
